//
//  RulerShowView.m
//  AmountBody
//
//  Created by smm on 2017/12/16.
//  Copyright © 2017年 RCMTM. All rights reserved.
//

#import "RulerShowView.h"

@implementation RulerShowView

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self loadUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self loadUI];
    }
    return self;
}
-(void)loadUI
{
    _nameLabel = [[UILabel alloc]init];
    [self addSubview:_nameLabel];
    _valueLabel = [[UILabel alloc]init];
    [self addSubview:_valueLabel];
    _valueText = [[UITextField alloc]init];
    [self addSubview:_valueText];
    _lineLabel = [[UILabel alloc]init];
    [self addSubview:_lineLabel];
    _rulerCustom = [[JSRulerView alloc] init];
    [self addSubview:_rulerCustom];
}
-(void)reloadData:(NSString*)dataStr
{
    _valueText.text = dataStr;
}

-(void)reloadUI:(EssentialModel *)model
{
    switch (model.essentialType) {
        case EssentialViewTypeForRulerWithSize:
        {
            [self reloadUIForSize:model];
        }
            break;
        case EssentialViewTypeForRulerWithNomal:
        {
            [self reloadUIForNomal:model];
        }
            break;
        case EssentialViewTypeForRulerWithPlaceOrder:
        {
            [self reloadUIForPlaceOrder:model];
        }
            break;
            
        default:
            break;
    }
}
-(void)reloadUIForNomal:(EssentialModel *)model
{
    _lineLabel.hidden = YES;
//    CGFloat viewW = self.frame.size.width;
    CGFloat t_viewH = 80;
    CGFloat biaoW = 5;
    CGFloat biaoH = biaoW;
    CGFloat jianGeW = 70;
//    CGFloat jianGeW = 85;
    _nameLabel.textColor = ShenZi_Color;
    _nameLabel.text = model.name;
    _nameLabel.font = Cell_Big_Font;
    [_nameLabel sizeToFit];
    _nameLabel.frame = CGRectMake(0, (t_viewH-Nomal_Label_H)/2.0, _nameLabel.frame.size.width, Nomal_Label_H);
    [self addSubview:_nameLabel];
    _valueText.text = model.value;
    _valueText.textColor = RGBColor(255, 66, 89);
    _valueText.font = Cell_Big_Font;
    _valueText.returnKeyType = UIReturnKeyNext;
    _valueText.keyboardType = UIKeyboardTypeNumberPad;
    [_valueText sizeToFit];
    _valueText.frame = CGRectMake(0, _nameLabel.frame.origin.y+_nameLabel.frame.size.height+5, _valueText.frame.size.width+5, Nomal_Label_H);
    _valueLabel.text = model.unit;
    _valueLabel.textColor = RGBColor(255, 66, 89);
    _valueLabel.font = Cell_Big_Font;
    [_valueLabel sizeToFit];
    _valueLabel.frame = CGRectMake(_valueText.frame.origin.x+_valueText.frame.size.width, _nameLabel.frame.origin.y+_nameLabel.frame.size.height+5, _valueLabel.frame.size.width, Nomal_Label_H);
    if (model.isMust) {
        _biaoLabel = [[UILabel alloc]initWithFrame:CGRectMake(_nameLabel.frame.origin.x+_nameLabel.frame.size.width, _nameLabel.frame.origin.y-5, biaoW, biaoH)];
        [_biaoLabel setBianKuangAndColor:RGBColorAlpha(227, 65, 85, 1)];
        [_biaoLabel setYuanJiaoForRadius:biaoH/2.0 andMasks:NO];
        [self addSubview:_biaoLabel];
    }
    
    [_rulerCustom mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(jianGeW);
        make.top.equalTo(self);
        make.right.equalTo(self);
        make.height.equalTo(@(t_viewH));
    }];
    
    
}

-(void)reloadUIForSize:(EssentialModel *)model
{
    _lineLabel.hidden = YES;
    CGFloat t_viewH = 100;
    CGFloat jianGeH = 0;
    CGFloat viewW = self.frame.size.width;
    _nameLabel.textColor = ShenZi_Color;
    _nameLabel.text = model.name;
    _nameLabel.font = Cell_Big_Font;
    [_nameLabel sizeToFit];
    _nameLabel.frame = CGRectMake(0, jianGeH, _nameLabel.frame.size.width, Nomal_Label_H);
    [self addSubview:_nameLabel];
    _valueText.text = model.value;
    _valueText.textColor = RGBColor(255, 66, 89);
    _valueText.font = Cell_Big_Font;
    _valueText.returnKeyType = UIReturnKeyNext;
    [_valueText sizeToFit];
    _valueText.frame = CGRectMake(_nameLabel.frame.size.width+_nameLabel.frame.origin.x+5, _nameLabel.frame.origin.y, _valueText.frame.size.width+5, Nomal_Label_H);
    _valueLabel.text = model.unit;
    _valueLabel.textColor = RGBColor(255, 66, 89);
    _valueLabel.font = Cell_Big_Font;
    [_valueLabel sizeToFit];
    _valueLabel.frame = CGRectMake(_valueText.frame.origin.x+_valueText.frame.size.width, _nameLabel.frame.origin.y, _valueLabel.frame.size.width, Nomal_Label_H);
    _rulerCustom.min = 0;
//    _rulerCustom.pointerSize = CGSizeMake(10, 10);
    _rulerCustom.pointer.image = [UIImage imageNamed:@"Triangle2"];
    _rulerCustom.max = ((int)_scaleArray.count-1);
    _rulerCustom.scaleIntervalTexts = _scaleArray;
    int index = 0;
    [_rulerCustom setValue:index animated:YES];
    [_rulerCustom mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(0);
        make.top.equalTo(self);
        make.right.equalTo(self);
        make.height.equalTo(@(t_viewH));
    }];
}

-(void)reloadUIForPlaceOrder:(EssentialModel *)model
{
    CGFloat t_viewH = 80;
    CGFloat jianGeH = 49;
    CGFloat jianGeW = 145;
    CGFloat viewW = self.frame.size.width;
    _nameLabel.textColor = ShenZi_Color;
    _nameLabel.text = model.name;
    _nameLabel.font = Cell_Big_Font;
    [_nameLabel sizeToFit];
    _nameLabel.frame = CGRectMake(0, jianGeH, _nameLabel.frame.size.width, Nomal_Label_H);
    [self addSubview:_nameLabel];
    _valueText.text = model.value;
    _valueText.textColor = RGBColor(255, 66, 89);
    _valueText.font = [UIFont systemFontOfSize:17.0];
    _valueText.returnKeyType = UIReturnKeyNext;
    [_valueText sizeToFit];
    _valueText.frame = CGRectMake(_nameLabel.frame.size.width+_nameLabel.frame.origin.x+5, _nameLabel.frame.origin.y, _valueText.frame.size.width+5, Nomal_Label_H);
    _valueLabel.text = model.unit;
    _valueLabel.textColor = QianZi_color;
    _valueLabel.font = Cell_Big_Font;
    [_valueLabel sizeToFit];
    _valueLabel.frame = CGRectMake(_valueText.frame.origin.x+_valueText.frame.size.width, _nameLabel.frame.origin.y, _valueLabel.frame.size.width, Nomal_Label_H);
    _lineLabel.hidden = NO;
    _lineLabel.frame = CGRectMake(0, t_viewH-1, _valueLabel.frame.origin.x+_valueLabel.frame.size.width, 1);
    _lineLabel.backgroundColor = QianZi_color;
    [_rulerCustom mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(jianGeW);
        make.top.equalTo(self);
        make.right.equalTo(self);
        make.height.equalTo(@(t_viewH));
    }];
}

@end
